function MyQueue(capacity) {
    this._array = new Array(capacity);
    this._front = 0;
    this._rear = 0;
}

MyQueue.prototype.enQueue = function(element) {
    if ((this._rear + 1) % this._array.length == this._front) {
        throw new Error(" 队列已满！");
    }
    this._array[this._rear] = element;
    this._rear = (this._rear + 1) % this._array.length;
}

MyQueue.prototype.deQueue = function() {
    if (this._rear == this._front) {
        throw new Error(" 队列已空！");
    }
    var deQueueElement = this._array[this._front];
    this._front = (this._front + 1) % this._array.length;
    return deQueueElement;
}
  
MyQueue.prototype.output = function() {
    for (var i = this._front; i != this._rear; i = (i + 1) % this._array.length) {
        console.log(this._array[i]);
    }
}
  
var myQueue = new MyQueue(6);
myQueue.enQueue(3);
myQueue.enQueue(5);
myQueue.enQueue(6);
myQueue.enQueue(8);

myQueue.enQueue(1);
myQueue.deQueue();
myQueue.deQueue();
myQueue.deQueue();
myQueue.enQueue(2);
myQueue.enQueue(4);
myQueue.enQueue(9);
myQueue.output();